import {
    request,
    requestNoAuth
} from '../../lib/java110/java110Request.js';
import url from '../../constant/url.js';

/**
 * 申请分销
 */
export function saveAffiliateUser(_data) {
    return new Promise((resolve, reject) => {
        let moreRooms = [];
        request({
            url: url.saveAffiliateUser,
            method: "POST",
            data: _data, //动态数据
            success: function(res) {
                let _data = res.data;
                if (_data.code == 0) {
                    resolve(_data);
                    return ;
                }
                reject(_data.msg);
            },
            fail: function(e) {
                reject(e);
            }
        });
    })
}

export function saveAffiliateLevel2User(_data) {
    return new Promise((resolve, reject) => {
        let moreRooms = [];
        request({
            url: url.saveAffiliateLevel2User,
            method: "POST",
            data: _data, //动态数据
            success: function(res) {
                let _data = res.data;
                if (_data.code == 0) {
                    resolve(_data);
                    return ;
                }
                reject(_data.msg);
            },
            fail: function(e) {
                reject(e);
            }
        });
    })
}

/**
 * 查询分销申请信息
 */
export function queryAffiliateUser(_data){
    return new Promise(
        (resolve, reject) => {
            request({
                url: url.queryAffiliateUser,
                method: "GET",
                data: _data,
                //动态数据
                success: function(res) {
                    if (res.statusCode == 200) {
                        let _affiliateUser = res.data;
                        resolve(_affiliateUser);
                        return;
                    }
                    reject();
                },
                fail: function(e) {
                    reject();
                }
            });
        })
}


export function deleteAffiliateLevel2User(_data) {
    return new Promise((resolve, reject) => {
        let moreRooms = [];
        request({
            url: url.deleteAffiliateLevel2User,
            method: "POST",
            data: _data, //动态数据
            success: function(res) {
                let _data = res.data;
                if (_data.code == 0) {
                    resolve(_data);
                    return ;
                }
                reject(_data.msg);
            },
            fail: function(e) {
                reject(e);
            }
        });
    })
}


export function queryAffiliateWithdrawal(_data){
    return new Promise(
        (resolve, reject) => {
            request({
                url: url.queryAffiliateWithdrawal,
                method: "GET",
                data: _data,
                //动态数据
                success: function(res) {
                    if (res.statusCode == 200) {
                        let _affiliateWithdrawal = res.data;
                        resolve(_affiliateWithdrawal);
                        return;
                    }
                    reject();
                },
                fail: function(e) {
                    reject();
                }
            });
        })
}

export function saveAffiliateWithdrawal(_data){
    return new Promise(
        (resolve, reject) => {
            request({
                url: url.saveAffiliateWithdrawal,
                method: "POST",
                data: _data,
                //动态数据
                success: function(res) {
                    let _data = res.data;
                    if (_data.code == 0) {
                        resolve(_data);
                        return ;
                    }
                    reject(_data.msg);
                },
                fail: function(e) {
                    reject();
                }
            });
        })
}


export function deleteAffiliateWithdrawal(_data) {
    return new Promise((resolve, reject) => {
        let moreRooms = [];
        request({
            url: url.deleteAffiliateWithdrawal,
            method: "POST",
            data: _data, //动态数据
            success: function(res) {
                let _data = res.data;
                if (_data.code == 0) {
                    resolve(_data);
                    return ;
                }
                reject(_data.msg);
            },
            fail: function(e) {
                reject(e);
            }
        });
    })
}

export function listAffiliateProduct(_dataObj){
    return new Promise(
        (resolve, reject) => {
            requestNoAuth({
                url: url.listAffiliateProduct,
                method: "GET",
                data: _dataObj,
                //动态数据
                success: function(res) {
                    if (res.data.code == 0) {
                        let _appraisets = res.data.data;
                        resolve(_appraisets);
                        return;
                    }
                    reject(res.data.msg);
                },
                fail: function(e) {
                    reject();
                }
            });
        })
}

/**
 * 查询分销订单
 */
export function queryAffiliateCommission(_data){
    return new Promise(
        (resolve, reject) => {
            request({
                url: url.queryAffiliateCommission,
                method: "GET",
                data: _data,
                //动态数据
                success: function(res) {
                    if (res.statusCode == 200) {
                        let _affiliateCommission = res.data;
                        resolve(_affiliateCommission);
                        return;
                    }
                    reject();
                },
                fail: function(e) {
                    reject();
                }
            });
        })
}


export function saveAffiliateRelation(_data){
    return new Promise(
        (resolve, reject) => {
            request({
                url: url.saveAffiliateRelation,
                method: "POST",
                data: _data,
                //动态数据
                success: function(res) {
                    let _data = res.data;
                    if (_data.code == 0) {
                        resolve(_data);
                        return ;
                    }
                    reject(_data.msg);
                },
                fail: function(e) {
                    reject();
                }
            });
        })
}
